
<form action="" method="post">  
    昵称：<input type="text" name="uname" placeholder="输入昵称"/><br>
		评论：<input type="rext" name="msg"  placeholder="输入内容"><br>
    <button type="submit">保存</button> 
</form>  
<?php  
	header("Content-type: text/html;charset=utf-8");
	#创建连接
	$conn=mysqli_connect("127.0.0.1","root","","xss");
	mysql_query("SET NAMES 'UTF8'"); 
	#检测连接
	if(!$conn){
		die("连接数据库失败！".mysqli_connect_error());
	}
	#创建表格
//	$sql = "CREATE TABLE conments (
//		uid INT(4) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
//		uname VARCHAR(30) NOT NULL,
//		msg TEXT
//	) CHARACTER SET utf8 COLLATE utf8_general_ci";
//
//	$conments = mysqli_query( $conn, $sql );
	
	#插入数据库
	if(isset($_POST["uname"])&& isset($_POST["msg"])){  
		$uname=$_POST['uname'];  
		$msg=$_POST['msg'];
		if(!empty($uname)&&!empty($msg)){
			$sql="insert into conments(uid,uname,msg) values(NULL,'$uname','$msg')";  
			$result=mysqli_query($conn,$sql);  
			if($result){
				echo "保存成功"; 
			}else{
				echo "保存失败：".$sql."<br>".mysqli_error($conn);
			}
		}
	}else{
		echo '<p style="color:#f00">请输入信息</p>';	
	}
?>